﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using Feedback.Business;
using Feedback.DataAccess;
using Feedback.Global;
using FeedbackWebClient.Common;

namespace FeedbackWebClient
{
    public partial class BusinessView : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (!IsValidInput()) return;
            var business = new Business
                               {
                                   FirstName = FirstName.Text.Trim(),
                                   LastName = LastName.Text.Trim(),
                                   Login = Email.Text.Trim(),
                                   Password = CryptographyHelper.CreateMD5Hash(Password.Text),
                                   LastUpdated = DateTime.Now
                               };
            var businessIdentification = new BusinessIdentification
                                             {
                                                 StoreName = StoreName.Text.Trim(),
                                                 BusinessEmail = BusinessMail.Text.Trim(),
                                                 LastUpdated = DateTime.Now
                                             };
            business.BusinessIdentifications.Add(businessIdentification);
            if(new BusinessLogic().SaveBusiness(business))
            {
                ShowMessage("Business has been saved successfully.", "Success");
            }
            else
            {
                ShowGenericErrorMessage();
            }

        }

        [WebMethod]
        public static bool IsBusinessEmailAddressExist(string value)
        {
            return new BusinessLogic().IsBusinessEmailAddressExist(value);
        }
    }
}